package com.power.using.mybomb.adapter;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.power.using.mybomb.bean.User;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 聪明一只哈 on 2020/3/23.
 * Time: 2020/3/23  14:30
 */
public class SearchUserAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<User> users=new ArrayList<>();

    public SearchUserAdapter() {
    }

    public void setDatas(List<User> list){
        users.clear();
        if(null!=list){
            users.addAll(list);
        }
    }

    public User getItem(int position){
        return users.get(position);
    }

    public OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SearchUserHolder(parent.getContext(),parent,onRecyclerViewListener);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((BaseViewHolder)holder).bindData(users.get(position));
    }

    @Override
    public int getItemViewType(int position) {
        return 1;
    }

    @Override
    public int getItemCount() {
        return users.size();
    }
}
